<template>
    <div class="decoration-box" :style="boxStyle">
        <div class="border" :style="borderStyle"></div>
        <div class="corner" v-if="showCorner"></div>
        <slot></slot>
    </div>
</template>

<script>
export default {
    props: {
        color: {
            type: String,
            default: '#4fd2dd'
        },
        showCorner: {
            type: Boolean,
            default: false
        }
    },
    computed: {
        boxStyle() {
            return {
                '--border-color': this.color
            }
        },
        borderStyle() {
            return {
                background: `linear-gradient(90deg, transparent, ${this.color}, transparent)`
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.decoration-box {
    position: relative;
    padding: 2px;
    overflow: hidden;

    .border {
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 2px;
        animation: flow 3s linear infinite;
    }

    .corner {
        position: absolute;
        width: 10px;
        height: 10px;
        border: 2px solid var(--border-color);

        :nth-child(1) {
            top: 0;
            left: 0;
            border-right: none;
            border-bottom: none;
        }

        :nth-child(2) {
            top: 0;
            right: 0;
            border-left: none;
            border-bottom: none;
        }

        :nth-child(3) {
            bottom: 0;
            left: 0;
            border-right: none;
            border-top: none;
        }

        :nth-child(4) {
            bottom: 0;
            right: 0;
            border-left: none;
            border-top: none;
        }
    }
}

@keyframes flow {
    0% {
        left: -100%;
    }

    100% {
        left: 100%;
    }
}
</style>